classdef spectra < handle
    
    properties
        data
        fitting
        label
        plotting
        constants
    end
    properties (Access = private)
        log
    end
    
    methods
        function obj = spectra(varargin)
            
            if nargin==0
                objS = initfield(struct);
                fNames = fieldnames(objS);
                for ii = 1:length(fNames)
                    obj.(fNames{ii}) = objS.(fNames{ii});
                end
                return;
            end
            
            if nargin == 1
                firstArg = varargin{1};
                if isa(firstArg, 'spectra') %  It is used when objects are passed as arguments.
                    for i=1:length(firstArg)
                        obj(i) = copy(firstArg(i));
                    end
                    return;
                end
                
                if isa(firstArg, 'struct')
                    objS = initfield(firstArg);
                    %validate(objS);
                    fNames = fieldnames(objS);
                    for ii = 1:length(fNames)
                        obj.(fNames{ii}) = firstArg.(fNames{ii});
                    end                    
                    return;
                end
                
            end
            
            if nargin == 3
                x=varargin{1};
                y=varargin{2};
                if length(varargin{3})==1
                    e = varargin{3}*ones(size(x));
                else
                    e=varargin{3};
                end
                
                [x, y, e]=validateData(x,y,e);
                
                objS=initfield(struct);
                obj=addData(objS,sp_data(x,y,e));
                return
            end
        end
        
        
        function objC = copy(obj)
            % clones spectra object
            objS = struct(obj);
            objC = spectra(objS);
        end
    end
end